package com.test.springmvc_demo.controller;

import com.test.springmvc_demo.entiy.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginController {
//    访问login方法，使用url： http://localhost:8080/login，跳转到login.html页面
    @RequestMapping("/login")
    public String openLoginPage(){
        //返回值直接写templates文件夹下的网页文件名称，不需要加.html后缀
        return "login";
    }
    //在login方法中接受用户提交的账号和密码,用户是通过网页使用form表单提交的数据
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(String username,String password){
        System.out.println("username:"+username+",password:"+password);
        return "index";
    }

    //方法参数使用实体类
    @RequestMapping(value = "/login2",method = RequestMethod.POST)
    public String login2(User user){
        System.out.println("username:"+user.getUsername()+",password:"+user.getPassword());
        return "index";
    }

    //@GetMapping("/login3")约等于@RequestMapping(value = "/login3",method = RequestMethod.GET)
    @GetMapping("/login3")
    public String login3(User user){
        System.out.println(user);
        return "index";
    }
}
